% write_brik
% Christopher J. Whalen
% University of Illinois
% 01/20/05 - Date Created
% 07/06/05 - Date Last Modified

% purpose - to write the output brik file whether unix or pc.

function write_brik(dig_brik,file,dir,exp,S,date)
         


file.brk_out = [file.brik_out '.brk'];
fid=fopen(file.brk_out,'w');
fwrite(fid,dig_brik,'int8');
fclose(fid);
if isunix
	cmd=['to3d -geomparent ' file.geom ' -fim ' ...
         '-prefix ' file.brik_out ' -view acpc 3Db:0:0:191:236:171:' file.brk_out ];
    unix(cmd);
    % to3d won't let you save the long filename with path so you must save
    % in pwd and move
    cmd = ['mv ' file.brik_out '+acpc.BRIK ' dir.brk ];
    unix(cmd);
    cmd = ['mv ' file.brik_out '+acpc.HEAD ' dir.brk ];
    unix(cmd);
    cmd = ['rm ' file.brk_out];
    unix(cmd);
    fprintf('\n');
    fprintf('Writing BRIK %s ...   \n',[dir.brk file.brik_out '+acpc.BRIK']);
    fprintf('Writing HEAD %s ... \n\n',[dir.brk file.brik_out '+acpc.HEAD']);
elseif ispc
    fprintf('Writing BRIK %s ... \n\n',file.brk_out);
end







